package 线程状态.线程的观测状态;

import jdk.nashorn.internal.ir.SetSplitState;

//thread.getState()获取线程的状态
public class test implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("/////");
    }
    public static void main(String[] args) throws InterruptedException {
        test test1 = new test();
        Thread thread = new Thread(test1);

        //为启动的线程
        System.out.println(thread.getState());
        //启动的线程
        thread.start();
        System.out.println(thread.getState());

        //捕捉运行中线程的状态
        while (thread.getState() != Thread.State.TERMINATED) {
            Thread.sleep(100);
            System.out.println(thread.getState());

            //获取主线程的状态
            System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getState());
        }

    }


}
